﻿namespace block_explorer.NoiseSystem.Nodes
{
    class TranslateDomain : INode
    {
        INode mSource;
        INode mXSource;
        INode mYSource;
        INode mZSource;

        public TranslateDomain(INode source, INode xSource, INode ySource, INode zSource)
        {
            mSource = source;
            mXSource = xSource;
            mYSource = ySource;
            mZSource = zSource;

            if (mXSource == null)
                mXSource = new Constant(0.0);
            if (mYSource == null)
                mYSource = new Constant(0.0);
            if (mZSource == null)
                mZSource = new Constant(0.0);
        }

        public TranslateDomain(INode source, double xSource, double ySource, double zSource)
        {
            mSource = source;
            mXSource = new Constant(xSource);
            mYSource = new Constant(ySource);
            mZSource = new Constant(zSource);
        }

        public double Value(double x, double y, double z)
        {
            return mSource.Value(x + mXSource.Value(x, y, z), y + mYSource.Value(x, y, z), z + mZSource.Value(x, y, z));
        }
    }
}
